package comi.gsi.db;

/**
 * thanks to
 * http://blog.taragana.com/index.php/archive/core-java-how-to-get-java
 * -source-code-line-number-file-name-in-code/!
 * 
 * @author klm
 * 
 */
public class LineStackTracePrinter {

	// original tutorial suggests items [2]
	// from arrays, but [3] works for android.
	// there you go..

	/**
	 * Get the current line number.
	 * 
	 * @return int - Current line number.
	 */
	public static int getLineNumber() {
		return Thread.currentThread().getStackTrace()[3].getLineNumber();
	}

	public static String getFileName() {
		return Thread.currentThread().getStackTrace()[3].getClassName()
				+ " (" + Thread.currentThread().getStackTrace()[3].getMethodName() + ")";
	}

	public static String scriviLineaDellErrore() {
		final String msg = " ********************* not implemented @ "
				+ LineStackTracePrinter.getFileName() + " line "
				+ LineStackTracePrinter.getLineNumber();
		System.err.println(msg);
		return msg;
	}
}
